package algotithm.acwing.sort.test429;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/18-10:02
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] str  = reader.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int[][] arr = new int[n][4];
        for (int i = 0; i < n ; i++) {
            String[] num = reader.readLine().split(" ");
            arr[i][0] = i+1;
            arr[i][1] = Integer.parseInt(num[0]);
            arr[i][2] = Integer.parseInt(num[1]);
            arr[i][3] = Integer.parseInt(num[2]);
        }
        reader.close();
        Arrays.sort(arr,new Comparator<int[]>(){
            @Override
            public int compare(int[] a , int[] b){     //传进来的是一行的数据，a = {90,67,80,1} b = {87,66,91,2}
                int s1 = a[1] + a[2] + a[3];
                int s2 = b[1] + b[2] + b[3];
                if(s1 != s2) {
                    return s2 - s1;       //总成绩按照从大到小排序
                }
                if(a[1] != b[1]) {
                    return b[1] - a[1];   // 语文成绩按照从大到小排序
                }
                return a[0] - b[0];       // 学号按照从小到大排序
            }
        });

        for (int i = 0; i < 5; i++) {
            System.out.println(arr[i][0] + " " + (arr[i][1] + arr[i][2] + arr[i][3]));
        }

    }

}
